﻿@using Aspire.Dashboard.Model
@using Aspire.Dashboard.Model.Otlp
@using Aspire.Dashboard.Resources
@implements IDialogContentComponent<FilterDialogViewModel>

@inject IStringLocalizer<Dialogs> Loc
@inject IStringLocalizer<Logs> LogsLoc

<EditForm EditContext="@EditContext" OnValidSubmit="@Apply">
    <DataAnnotationsValidator />

    <FluentStack Orientation="Orientation.Vertical" VerticalGap="8">
        <FluentCombobox TOption="SelectViewModel<string>"
                        Placeholder="@Loc[nameof(Dialogs.FilterDialogFieldPlaceholder)]"
                        Items="@_parameters"
                        @bind-SelectedOption="@_formModel.Parameter"
                        Width="100%"
                        Height="500px"
                        OptionText="@(c => c.Name)"
                        OptionDisabled="@(c => c.Id is null)" />

        <FluentSelect TOption="SelectViewModel<FilterCondition>" Items="@_filterConditions" @bind-SelectedOption="@_formModel.Condition" aria-label="@Loc[Dialogs.FilterDialogConditionSelectLabel]" OptionText="@(i => i.Name)" Width="100%" />

        <FluentTextField @bind-Value="_formModel.Value" Placeholder="@Loc[nameof(Dialogs.FilterDialogTextValuePlaceholder)]" />
        <ValidationMessage For="() => _formModel.Value" />

        <FluentStack Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.Right">
            <FluentButton OnClick="Cancel">@Loc[nameof(Dialogs.FilterDialogCancelButtonText)]</FluentButton>
            <FluentButton Color="Color.Primary" Type="ButtonType.Submit">@Loc[nameof(Dialogs.FilterDialogApplyFilterButtonText)]</FluentButton>
            @if (Content.Filter is not null)
            {
                <FluentButton Appearance="Appearance.Stealth" aria-label="@Loc[nameof(Dialogs.FilterDialogRemoveFilterButtonText)]" OnClick="Delete"><FluentIcon Value="@(new Icons.Regular.Size16.Delete())" /></FluentButton>
            }
        </FluentStack>
    </FluentStack>

</EditForm>
